package org.example.basics;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;

public class Demo2 {
    public static void main(String[] args) {
//        test1();
//        test3();
        test4();
    }

    private static void test4() {
        Day[] days2 = Day.values();
        System.out.println("day2:" + Arrays.toString(days2));
        Day day = Day.valueOf("MONDAY");
        System.out.println("day:" + day);
    }

    private static void test3() {
        //创建枚举数组
        Day[] days = new Day[]{Day.MONDAY, Day.TUESDAY, Day.WEDNESDAY,
                Day.THURSDAY, Day.FRIDAY, Day.SATURDAY, Day.SUNDAY};

        for (int i = 0; i < days.length; i++) {
            System.out.println("day[" + i + "].ordinal():" + days[i].ordinal());
        }
        System.out.println("-------------------------------------");

        //通过compareTo方法比较,实际上其内部是通过ordinal()值比较的
        System.out.println("days[0].compareTo(days[1]):"
                + days[0].compareTo(days[1]));
        System.out.println("days[0].compareTo(days[1]):"
                + days[0].compareTo(days[2]));

        //获取该枚举对象的Class对象引用,当然也可以通过getClass方法
        Class<?> clazz = days[0].getDeclaringClass();
        System.out.println("clazz:" + clazz);
        System.out.println("-------------------------------------");

        //name()
        System.out.println("days[0].name():" + days[0].name());
        System.out.println("days[1].name():" + days[1].name());
        System.out.println("days[2].name():" + days[2].name());
        System.out.println("days[3].name():" + days[3].name());
        System.out.println("-------------------------------------");

        System.out.println("days[0].toString():" + days[0].toString());
        System.out.println("days[1].toString():" + days[1].toString());
        System.out.println("days[2].toString():" + days[2].toString());
        System.out.println("days[3].toString():" + days[3].toString());
        System.out.println("-------------------------------------");

        Day d = Enum.valueOf(Day.class, days[0].name());
        Day d2 = Day.valueOf(Day.class, days[0].name());
        System.out.println("d:" + d);
        System.out.println("d2:" + d2);
    }

    private static void test1() {
        tellItLikeItIs(Day.MONDAY);    // 周一各种不在状态
        tellItLikeItIs(Day.SATURDAY);  // 周末给人的感觉是最棒的
        tellItLikeItIs(Day.SUNDAY);    // 周末给人的感觉是最棒的
    }

    public static void tellItLikeItIs(Day day) {
        switch (day) {
            case SATURDAY, SUNDAY:
                System.out.println("周末给人的感觉是最棒的");
                break;
            default:
                System.out.println("周内感觉就那样吧。。。");
                break;
        }
    }
}

enum SingletonEnum {
    INSTANCE;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

enum Day {
    MONDAY("Monday", "Mon."),
    TUESDAY("Tuesday", "Tue."),
    WEDNESDAY("Wednesday", "Wen."),
    THURSDAY("Thursday", "Thu."),
    FRIDAY("Friday", "Fri."),
    SATURDAY("Saturday", "Sat."),
    SUNDAY("Sunday", "Sun.");

    private final String x, y;

    Day(String x, String y) {
        this.x = x;
        this.y = y;
    }
}


